// src/store/modules/user.js
import { Map } from 'immutable'
import * as types from '../types'
const reducer = (state = Map({
  adminname: localStorage.getItem('adminname') || '',
  token: localStorage.getItem('token') || '',
  role: localStorage.getItem('role') * 1 || 1,
  loginState: localStorage.getItem('loginState') === 'true'
}), { type, payload }) => {
  switch (type) {
    case types.CHANGE_ADMIN_NAME:
      localStorage.setItem('adminname', payload) //存本地
      return state.set('adminname', payload) // 修改状态管理器
    case types.CHANGE_TOKEN:
      localStorage.setItem('token', payload) //存本地
      return state.set('token', payload) // 修改状态管理器
    case types.CHANGE_ROLE:
      localStorage.setItem('role', payload) //存本地
      return state.set('role', payload) // 修改状态管理器
    case types.CHANGE_LOGIN_STATE:
      localStorage.setItem('loginState', payload) //存本地
      return state.set('loginState', payload) // 修改状态管理器
    default:
      return state
  }
}

export default reducer